;Exercise 1.5.  Ben Bitdiddle has invented a test to determine whether the interpreter
;he is faced with is using applicative-order evaluation or normal-order evaluation.
;He defines the following two procedures:

(define (p) (p))

(define (test x y)
  (if (= x 0)
      0
      y))

;Then he evaluates the expression

(test 0 (p))

;What behavior will Ben observe with an interpreter that uses applicative-order evaluation? What behavior will he observe with an interpreter that uses normal-order evaluation? Explain your answer. (Assume that the evaluation rule for the special form if is the same whether the interpreter is using normal or applicative order: The predicate expression is evaluated first, and the result determines whether to evaluate the consequent or the alternative expression.)

;ANSWER:

;In an interpreter with applicative-order-evaluation the function call would enter an infinite recursion
;loop eventually leading to a stack overflow. This happened because p is evaluated and then
;applied to the function 'test'.

; In a normal-order-evaluation environment, the evaluation of p would be delayed until the time the intepreter needed to expand the p definition. In the (test 0 (p)) case, p would never be expanded and in consequence, the function invocation wouldn't loop eternally, but return 0 to the caller